package leetcode.editor.cn.q1_300.q100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author qidi
 * @date 2022-01-07 14:35:07
 */
class Q0118_PascalsTriangle {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public List<List<Integer>> generate(int numRows) {
            List<List<Integer>> reslut = new ArrayList<>();
            reslut.add(Arrays.asList(1));
            if (numRows == 1) return reslut;

            for (int size = 2; size <= numRows; size++) {
                List<Integer> cur = new ArrayList<>();
                for (int i = 0; i < size; i++) {
                    if (size - 1 == i || i == 0) {
                        cur.add(1);
                    } else {
                        cur.add(reslut.get(size - 2).get(i - 1) + reslut.get(size - 2).get(i));
                    }
                }
                reslut.add(cur);
            }
            return reslut;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0118_PascalsTriangle().new Solution();
        System.out.println(solution.generate(3));
        System.out.println(solution.generate(4));
        System.out.println(solution.generate(5));
        System.out.println(solution.generate(6));
    }
}